/***************************************************************
 * cs.cpp: contrast stretching
 * 
 * Author: Hairong Qi (C) hqi@utk.edu
 * 
 * Created: 01/24/06
 *
 ***************************************************************/

#include "Image.h"
#include "Dip.h"
#include <iostream>
#include <cmath>

using namespace std;

/**
 * Contrast stretching. s = m*r + b where
 * s: enhanced pixel intensity
 * r: original pixel intensity
 * @param inimg Input image
 * @param m Slope
 * @param b Intercept
 * @return Contrast stretched image.
 */
Image cs(Image &inimg, float m, float b) {
  Image outimg;
  int i, j, k;
  int nr, nc, ntype, nchan;

  // allocate memory
  nr = inimg.getRow();
  nc = inimg.getCol();
  ntype = inimg.getType();
  nchan = inimg.getChannel();

  outimg.createImage(nr, nc, ntype);

  // perform contrast stretching
  for (i=0; i<nr; i++)
    for (j=0; j<nc; j++)
      for (k=0; k<nchan; k++)
        outimg(i,j,k) = m * inimg(i,j,k) + b;

  return outimg;
}


